package mil.af.amc.adpetracker.model;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import java.util.HashSet;

/**
 * Report of Survey object
 *
 * Represents a ROS/Waiver package
 *
 * @author TSgt Jason Ferguson
 */

@Entity
@Table(name="T_ROS")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Ros implements Serializable, Comparable<Ros> {

    private int id;
    private String name;
    private RosType type;
    private AdpeAccount adpeAccount;
    private String trackingNumber;
    private String internalPackageName;
    private String rosOfficer;
    private Date initDate;
    private Date closeDate;
    private Status status;
    private Set<EquipmentItem> identifiedItems = new HashSet<EquipmentItem>();

    @Id
    @Column(name="ROSID")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "SEQ_ROS")
    @SequenceGenerator(name="SEQ_ROS", sequenceName = "S_ROS")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Column(name="NAME")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Enumerated(value = EnumType.ORDINAL)
    @Column(name="TYPE")
    public RosType getType() {
        return type;
    }

    public void setType(RosType type) {
        this.type = type;
    }

    @ManyToOne
    @JoinColumn(name="ADPEACCT")
    public AdpeAccount getAdpeAccount() {
        return adpeAccount;
    }

    public void setAdpeAccount(AdpeAccount adpeAccount) {
        this.adpeAccount = adpeAccount;
    }

    @Column(name="TRACKINGNUMBER")
    public String getTrackingNumber() {
        return trackingNumber;
    }

    public void setTrackingNumber(String trackingNumber) {
        this.trackingNumber = trackingNumber;
    }

    @Column(name="INTERNALNAME", length = 25)
    public String getInternalPackageName() {
        return internalPackageName;
    }

    public void setInternalPackageName(String internalPackageName) {
        this.internalPackageName = internalPackageName;
    }

    @Column(name="ROSOFFICER")
    public String getRosOfficer() {
        return rosOfficer;
    }

    public void setRosOfficer(String rosOfficer) {
        this.rosOfficer = rosOfficer;
    }

    @Temporal(TemporalType.DATE)
    @Column(name="INITDATE")
    public Date getInitDate() {
        return initDate;
    }

    public void setInitDate(Date initDate) {
        this.initDate = initDate;
    }

    @Temporal(TemporalType.DATE)
    @Column(name="CLOSEDATE")
    public Date getCloseDate() {
        return closeDate;
    }

    public void setCloseDate(Date closeDate) {
        this.closeDate = closeDate;
    }

    @Enumerated(EnumType.ORDINAL)
    @Column(name="STATUS")
    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    //@OneToMany
    //@JoinTable(name="T_ROS_ITEM",
    //        joinColumns = @JoinColumn(name="ROSID"),
    //        inverseJoinColumns = @JoinColumn(name="ITEMID"))
    @OneToMany(mappedBy = "rosPackage")
    public Set<EquipmentItem> getIdentifiedItems() {
        return identifiedItems;
    }

    public void setIdentifiedItems(Set<EquipmentItem> identifiedItems) {
        this.identifiedItems = identifiedItems;
    }

    @Transient
    public int getPackageSize() {
        return identifiedItems.size();
    }

    public int compareTo(Ros o) {

        return this.getTrackingNumber().toUpperCase().compareTo(o.getTrackingNumber().toUpperCase());

    }
}
